package com.jquest;

import org.newdawn.slick.*;
import org.newdawn.slick.geom.Ellipse;
import com.jquest.data.Player;
import com.jquest.data.Map;
import com.jquest.collision.CollisionMask;
import com.jquest.misc.ResourceMap;
import com.jquest.misc.Tileset;
import com.jquest.io.TilesetLoader;

/**
 * Created by IntelliJ IDEA.
 * User: Johan
 * Date: 2009-dec-11
 * Time: 03:21:31
 * To change this template use File | Settings | File Templates.
 */
public class Demo extends BasicGame {
    Map map;
    Player p;
    public static Tileset ts;

    public static void main(String[] args) {
        try {
            System.setProperty("java.library.path", "./lib/native");
            System.loadLibrary("lwjgl");
            System.loadLibrary("OpenAL32");
            System.loadLibrary("jinput-raw");
            System.loadLibrary("jinput-dx8");
            AppGameContainer app = new AppGameContainer(new Demo("Glory Quest"));
            app.setTargetFrameRate(60);
            app.setDisplayMode(800, 600, false);
            app.start();
        } catch(Exception e) {}
    }

    public Demo(String name) {
        super(name);
    }

    public void init(GameContainer gc) {
        try {
            loadResources();
            map = Map.fromFile("./res/maps/test.map");
            p = new Player(32, 32, new SpriteSheet(ResourceMap.getString("Link"), 16, 24, Color.white, 1), 32, map);
            p.setCollisionMask(new CollisionMask(new Ellipse(0, 0, 8, 5), p));
            p.getCollisionMask().setOffset(0, 5);

        } catch(Exception e) {
            e.printStackTrace();
        }


    }

    public Map getMap() {
        return map;
    }

    public void render(GameContainer gc, Graphics g) {
        map.render(g);
        p.render(g, null);
    }

    public void update(GameContainer gc, int time) {
        map.update(time);
        p.update(gc, time);
    }

    public void loadResources() throws SlickException {
        TilesetLoader tsl = new TilesetLoader();
        ts = tsl.load("./res/tilesets/demo.zip");
        ResourceMap.add("Link", "./res/sprites/link/link.PNG");
    }

}
